package Servlet;

import com.cyy.dao.userDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/saveInfo")
public class saveInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userName=request.getSession().getAttribute("name").toString();
        String pwd=request.getParameter("pwd");
        String phone=request.getParameter("phone");
        String address=request.getParameter("address");
        userDao userDao = new userDao();
        try {
                userDao.update(userName, pwd,phone,address);
        } catch (SQLException | ClassNotFoundException throwables) {
            throwables.printStackTrace();
        }
        request.getSession().setAttribute("address",address);
        request.getSession().setAttribute("phone",phone);
        request.getRequestDispatcher("/showMyInfo").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
